package com.smartcommunity.controller.villageGroup;

import com.smartcommunity.bean.model.Result;
import com.smartcommunity.entity.villagegroup.VillageGroup;
import com.smartcommunity.service.villageGroup.impl.VillageGroupServiceImpl;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @ClassName: VillageGroupController
 * @Description: 小区设备分组控制器
 * @author: cp
 * @Date: 2020/7/29 15:01
 * @Company:
 * @version V2.1.0
 */
@RestController
@RequestMapping("/villageGroup")
@Api(value = "小区-设备分组",tags = "小区设备分组")
@Slf4j
public class VillageGroupController {

    @Autowired
    private VillageGroupServiceImpl villageGroupService;
    @PostMapping("/addGroup")
    @ApiOperation(value = "添加小区分组",notes = "添加小区分组")
    public Result addGroup(@RequestBody VillageGroup villageGroup){
        villageGroupService.addGroup(villageGroup);
        return Result.ok(villageGroup);
    }

    @DeleteMapping("/remove")
    @ApiOperation(value = "删除小区分组",notes = "删除小区分组")
    public Result remove(@RequestParam Long id){
        villageGroupService.removeGroup(id);
        return Result.ok();
    }

    @PostMapping("/update")
    @ApiOperation(value = "更新小区分组",notes = "更新小区分组")
    public Result update(@RequestBody VillageGroup villageGroup){
        villageGroupService.updateGroup(villageGroup);
        return Result.ok(villageGroup);
    }

    @PostMapping("/saveGroup")
    @ApiOperation(value = "批量保存小区分组信息",notes = "批量保存小区分组信息")
    public Result saveGroup(@RequestBody List<VillageGroup> villageGroup){
        villageGroupService.saveGroup(villageGroup);
        return Result.ok();
    }

    @PostMapping("/delDeviceByGroup")
    @ApiOperation(value = "批量删除小区分组设备根据分组id",notes = "批量删除小区分组设备根据分组id")
    public Result delDeviceByGroup(List<Long> groupId){
        villageGroupService.delDeviceByGroup(groupId);
        return Result.ok();
    }

    @PostMapping("/delDeviceByDevice")
    @ApiOperation(value = "批量删除小区分组设备根据设备id",notes = "批量删除小区分组设备根据设备id")
    public Result delDeviceByDevice(List<String> deviceIds){
        villageGroupService.delDeviceByDevice(deviceIds);
        return Result.ok();
    }
}
